/**
 * 资源相关请求模块
 */
import request from '@/utils/request'

interface Resource {
  name: string
  url: string
  description: string
  categoryId: number
  selected: boolean
}
interface SaveOrUpdateResource {
  name: string
  url: string
  description: string
  categoryId: number
  id: number
}
export const getResourcePages = (data: Resource) => {
  return request({
    method: 'POST',
    url: '/boss/resource/getResourcePages',
    data
  })
}
export const saveOrUpdate = (data: SaveOrUpdateResource) => {
  return request({
    method: 'POST',
    url: '/boss/resource/saveOrUpdate',
    data
  })
}

export const getResource = (id: number) => {
  return request({
    method: 'GET',
    url: `/boss/resource/${id}`
  })
}
export const deleteResource = (id: number) => {
  return request({
    method: 'DELETE',
    url: `/boss/resource/${id}`
  })
}

export const getRoleResources = (id: string | number = -1) => {
  return request({
    method: 'GET',
    url: `/boss/resource/getRoleResources?roleId=${id}`
  })
}
// 分配菜单
interface AllocateRoleResources {
  roleId: number
  resourceIdList: number[]
}
export const allocateRoleResources = (data: AllocateRoleResources) => {
  return request({
    method: 'POST',
    url: '/boss/resource/allocateRoleResources',
    data
  })
}
